package com.iims.common.core.page;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import springfox.documentation.annotations.ApiIgnore;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;

/**
 * 表格分页数据对象
 *
 * @author fanpei
 */
@ApiModel("列表数据响应实体")
@Data
public class TableDataInfo implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 数据
     */
    @ApiModelProperty(value = "返回数据", required = false)
    private TableDataValue data;

    /**
     * 消息状态码
     */
    @ApiModelProperty(value = "返回码，200为正常", required = true)
    private int code;

    /**
     * 消息内容
     */
    @ApiModelProperty(value = "消息提示", required = true)
    private String msg;

    /**
     * 表格数据对象
     */
    public TableDataInfo() {
        data = new TableDataValue();
    }

    /**
     * 分页
     *
     * @param list  列表数据
     * @param total 总记录数
     */
    public TableDataInfo(List<?> list, int total) {
        setRows(list);
        setTotal(total);
    }

    public void setTotal(long total) {
        this.data.setTotal(total);
    }

    public void setRows(List<?> rows) {
        this.data.setRows(rows);
    }

    public void setPageInfo(PageInfo info) {
        this.data.setTotal(info.getTotal());
        this.data.setPageNum(info.getPageNum());
        this.data.setPageSize(info.getPageSize());
        this.data.setPageTotal(info.getPages());
    }


}
